package com.agritech.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 环境监测类，作为被观察者
 */
public class EnvironmentMonitor {
    private final List<EnvironmentObserver> observers = new ArrayList<>();
    private EnvironmentData environmentData;

    public void registerObserver(EnvironmentObserver observer) {
        observers.add(observer);
    }

    public void removeObserver(EnvironmentObserver observer) {
        observers.remove(observer);
    }
    /*通知方法*/
    public void notifyObservers() {
        for (EnvironmentObserver observer : observers) {
            observer.update(environmentData);
        }
    }

    public void setEnvironmentData(EnvironmentData data) {
        this.environmentData = data;
        notifyObservers();
    }
}